package org.spring.aicloud.task;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.xxl.job.core.handler.annotation.XxlJob;
import jakarta.annotation.Resource;
import org.spring.aicloud.entity.User;
import org.spring.aicloud.service.IUserService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @author yexiebao
 * @date 2025/6/3
 * @description:存放定时任务
 */

@Component
public class TimedTask {
    @Resource
    private IUserService userService;
    @Value("${system.user.usecount}")
    private Integer useCount;
    /**
     * 重置用户使用次数的定时任务
     */
    @XxlJob(("resetUserUseCount"))
    public void resetUserUseCount() {
        UpdateWrapper<User> updateWrapper = new UpdateWrapper<>();
        updateWrapper.set("usecount", useCount);
        if(!userService.update(updateWrapper)){
            //todo:调用通知中心通知负责人排查和解决问题
            System.out.println("重置次数失败");
        };
        System.out.println("重置用户使用次数");
    }
}
